home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / DCLAP 6d / dclap6d / DBio.more / UGridStuff.inc.p < prev    next >
Text File  |  1996-07-05  |  7KB  |  283 lines

  1. { UGridStuff.inc.p  }
  2. { Copyright 1992 by d.g.gilbert, for SeqApp }
  3.  
  4. {$S UGridStuff }
  5.  
  6.  
  7.  
  8.  
  9. {    TRCshifter -------------------------- }
  10.  
  11. CONST
  12.         cRCShift    = 2020;
  13.         
  14. PROCEDURE TRCshifter.IRCshifter(itsDocument: TDocument; 
  15.                                 itsView: TGridView; itsSibling: TGridView;
  16.                                 RowOrCol: VHSelect; atRC: integer);
  17. VAR
  18.     vwr:            VRect;
  19.     itsMouse: Point;
  20.     itsVMouse: VPoint;
  21. BEGIN
  22.     GetMouse( itsMouse);  
  23.     itsView.QDToViewPt( itsMouse, itsVMouse);
  24.     ITracker(cRCShift, itsDocument, kCanUndo, kCausesChange{kDoesNotCauseChange} ,
  25.                      itsDocument, itsView, itsView.GetScroller(FALSE), itsVMouse);      
  26.  
  27.     fConstrainsMouse := true;
  28.     fGrid     := itsView;
  29.     fSibling:= itsSibling;
  30.     fNewRC := atRC;
  31.     fOldRC := fNewRC;
  32.     fRowCol:= RowOrCol;
  33.     fGrid.RowToVRect( 1, fGrid.fNumOfRows, vwr);
  34.     fBounds:= vwr;
  35. END;
  36.  
  37.  
  38.  
  39. FUNCTION TRCshifter.TrackMouse(aTrackPhase: TrackPhase; VAR anchorPoint, previousPoint,
  40.                                  nextPoint: VPoint; mouseDidMove: BOOLEAN): TTracker; OVERRIDE;
  41. VAR
  42.     aCell: GridCell;
  43. BEGIN
  44.     IF aTrackPhase = trackRelease then BEGIN
  45.         aCell    := fGrid.VPointToLastCell(nextPoint);
  46.         fNewRC:= aCell.vh[fRowCol];
  47.         END;
  48.     TrackMouse := SELF;
  49. END;
  50.  
  51.  
  52.  
  53. PROCEDURE TRCshifter.DrawFeedback( anchorPoint, nextPoint: VPoint);
  54. VAR
  55.     qdr: Rect;
  56.     vwr: VRect;
  57.     aCell: GridCell;
  58. BEGIN
  59.     aCell    := fGrid.VPointToLastCell(nextPoint);
  60.     IF fRowCol = v then BEGIN
  61.         fGrid.RowToVRect(aCell.v, 1, vwr);
  62.         fGrid.ViewToQDRect( vwr, qdr);
  63.         FrameRect( qdr);
  64.         if fSibling<>NIL then begin
  65.             if fSibling.Focus then ;
  66.             fSibling.RowToVRect(aCell.v, 1, vwr);
  67.             fSibling.ViewToQDRect( vwr, qdr);
  68.             FrameRect( qdr);
  69.             if fGrid.Focus then ;
  70.             END;
  71.         END
  72.  
  73.     ELSE BEGIN
  74.         fGrid.ColToVRect(aCell.h, 1, vwr);
  75.         fGrid.ViewToQDRect( vwr, qdr);
  76.         FrameRect( qdr);
  77.         if fSibling<>NIL then begin
  78.             if fSibling.Focus then ;
  79.             fSibling.ColToVRect(aCell.h, 1, vwr);
  80.             fSibling.ViewToQDRect( vwr, qdr);
  81.             FrameRect( qdr);
  82.             if fGrid.Focus then ;
  83.             END;
  84.         END;
  85. END;
  86.     
  87. PROCEDURE TRCshifter.TrackFeedback(aTrackPhase: TrackPhase; 
  88.                             anchorPoint, previousPoint, nextPoint: VPoint; 
  89.                             mouseDidMove, turnItOn: BOOLEAN); OVERRIDE;
  90. VAR  pState: PenState;
  91. BEGIN
  92.     IF mouseDidMove THEN BEGIN
  93.         GetPenState(pState);
  94.         PenMode(patXOR);  
  95.         DrawFeedback( anchorPoint, nextPoint); 
  96.         SetPenState(pState);
  97.         END;
  98. END;
  99.  
  100.  
  101.  
  102.  
  103. PROCEDURE TRCshifter.TrackConstrain(aTrackPhase: TrackPhase; 
  104.                         anchorPoint, previousPoint: VPoint; VAR nextPoint: VPoint;
  105.                         mouseDidMove: BOOLEAN); OVERRIDE;
  106. var vhs: vhSelect;
  107.       d    : integer;
  108. BEGIN
  109.     if nextpoint.h < fBounds.left then nextPoint.h:= fBounds.left
  110.     else if nextpoint.h > fBounds.right then nextPoint.h:= fBounds.right;
  111.     if nextpoint.v < fBounds.top then nextPoint.v:= fBounds.top
  112.     else if nextpoint.v > fBounds.bottom then nextPoint.v:= fBounds.bottom;
  113. END;
  114.  
  115.  
  116.  
  117.  
  118. PROCEDURE TRCshifter.DoShift( fromRC, toRC: integer);
  119. {! OVERRIDE THIS.
  120.     need to know details of storage here. 
  121.      we aren't changing num of rows or cols, 
  122.     just shifting (private) contents of row or col
  123. }
  124. BEGIN
  125.  
  126. END;
  127.  
  128. PROCEDURE TRCshifter.DoIt; OVERRIDE;
  129. BEGIN
  130.     if fNewRC <> fOldRC then BEGIN
  131.         DoShift(fOldRC, fNewRC);
  132.         END;
  133. END;
  134.  
  135.  
  136.  
  137. PROCEDURE TRCshifter.UndoIt; OVERRIDE;
  138. BEGIN
  139.     if fNewRC <> fOldRC then BEGIN
  140.         DoShift(fNewRC, fOldRC);
  141.         END;
  142. END;
  143.  
  144.  
  145.  
  146. PROCEDURE TRCshifter.RedoIt; OVERRIDE;
  147. BEGIN
  148.     DoIt;
  149. END;
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159. { TListSlider ------------------------}
  160.  
  161.  
  162. PROCEDURE TListSlider.IListSlider( itsGridView: TGridView; itsList: TList;
  163.                                                                         RowOrCol: VHSelect; atRC: integer);
  164. BEGIN
  165.     IRCShifter(itsGridView.fDocument, itsGridView, NIL, RowOrCol, atRC);
  166.     fList:= itsList;
  167.     fOldTop:= fGrid.FirstSelectedCell.vh[fRowCol];
  168.     fOldBottom:= fGrid.LastSelectedCell.vh[fRowCol];
  169.     fOldSelection:= NewRgn; FailNil( fOldSelection);
  170.     fNewSelection:= NewRgn; FailNIL( fNewSelection);
  171.     CopyRgn( itsGridView.fSelections, fOldSelection);
  172.     CopyRgn( fOldSelection, fNewSelection);
  173.     IF fGrid.Focus THEN ;
  174.     IF (fRowCol = v) THEN BEGIN
  175.         {- fTrackBottom:= fBounds.bottom - (fOldBottom-fOldTop);}
  176.         fTrackBottom:= fBounds.bottom;
  177.         fTrackRight:= fBounds.right;
  178.         END
  179.     ELSE BEGIN
  180.         fTrackBottom:= fBounds.bottom;
  181.         {-fTrackRight:= fBounds.right - (fOldBottom-fOldTop);}
  182.         fTrackRight:= fBounds.right;
  183.         END;
  184. END;
  185.  
  186.  
  187. PROCEDURE TListSlider.Free; OVERRIDE;
  188. BEGIN
  189.     IF (fOldSelection<>NIL) THEN DisposeRgn( fOldSelection);
  190.     fOldSelection:= NIL;
  191.     IF (fNewSelection<>NIL) THEN DisposeRgn( fNewSelection);
  192.     fNewSelection:= NIL;
  193.     INHERITED Free;
  194. END;
  195.  
  196.  
  197. PROCEDURE TListSlider.DoShift( fromRC, toRC: integer); OVERRIDE;
  198. VAR    
  199.     tmpList: TList; 
  200.     i, newtop, newAt, newbottom,nShift, dist: integer;
  201.     vLoc    : VRect;
  202.     tmpRgn: RgnHandle;
  203. BEGIN
  204.     dist:= toRC - fromRC;
  205.     newTop:= fOldTop + dist;
  206.     newBottom:= fOldBottom + dist;
  207.     nShift:= fOldBottom - fOldTop + 1;
  208.     tmpList:= NewList;
  209.     FailNIL( tmpList);
  210.     for i:= fOldBottom DOWNTO fOldTop DO BEGIN
  211.         tmpList.InsertFirst( fList.At( i));
  212.         fList.AtDelete( i);
  213.         END;
  214.     if (dist<0) THEN BEGIN
  215.         newAt:= newTop;
  216.         IF (fRowCol = v) THEN fGrid.RowToVRect( newtop, fOldBottom - newtop+1, vLoc)
  217.         ELSE fGrid.ColToVRect( newtop, fOldBottom - newtop + 1, vLoc);
  218.         END
  219.     ELSE BEGIN
  220.         newAt:= newTop - (newBottom - newTop){ + 1};
  221.         IF (fRowCol = v) THEN fGrid.RowToVRect( fOldTop, newbottom -  fOldTop+1, vLoc)
  222.         ELSE fGrid.ColToVRect( fOldTop, newbottom - fOldTop+1, vLoc);
  223.         END;
  224.     for i:= nShift DOWNTO 1 DO 
  225.         fList.InsertBefore( newAt, tmpList.At(i));
  226.     tmpList.Free;
  227.     fGrid.InvalidateVrect( vLoc);
  228.  
  229.     CopyRgn( fOldSelection, fNewSelection);
  230.     IF (fRowCol = v) THEN OffsetRgn( fNewSelection, 0, dist)
  231.     ELSE OffsetRgn( fNewSelection, dist, 0);
  232.     fGrid.SetSelection( fNewSelection, NOT kExtend, kHighlight, kSelect);
  233.  
  234.     {! tell where our selection is now, for undo/redo }
  235.     fOldTop:= newTop; {?? or is it fOldTop:= fOldTop + dist - (size-1) }
  236.     fOldBottom:= newBottom; {"" }
  237.     tmpRgn:= fOldSelection;
  238.     fNewSelection:= fOldSelection;
  239.     fOldSelection:= tmpRgn;
  240. END;
  241.  
  242.  
  243. PROCEDURE TListSlider.DrawFeedback( anchorPoint, nextPoint: VPoint); OVERRIDE;
  244. VAR
  245.     aSelectRgn: RgnHandle;
  246.     delta        : longint;
  247. BEGIN
  248.     aSelectRgn:= NewRgn;
  249.     fGrid.CellsToPixels( fGrid.fSelections, aSelectRgn); 
  250.     IF (fRowCol = v) THEN BEGIN
  251.         delta:= nextPoint.v - anchorPoint.v;
  252.         OffsetRgn( aSelectRgn, 0, delta);
  253.         END
  254.     ELSE BEGIN
  255.         delta:= nextPoint.h - anchorPoint.h;
  256.         OffsetRgn( aSelectRgn, delta, 0);
  257.         END;
  258.     FrameRgn( aSelectRgn);
  259.     DisposeRgn( aSelectRgn);
  260. END;
  261.  
  262.  
  263. PROCEDURE TListSlider.TrackConstrain(aTrackPhase: TrackPhase; 
  264.                         anchorPoint, previousPoint: VPoint; VAR nextPoint: VPoint;
  265.                         mouseDidMove: BOOLEAN); OVERRIDE;
  266. BEGIN
  267.     if nextpoint.h < fBounds.left then
  268.         nextPoint.h:= fBounds.left
  269.     else if nextpoint.h > fTrackright then
  270.         nextPoint.h:= fTrackright;
  271.         
  272.     if nextpoint.v < fBounds.top then
  273.         nextPoint.v:= fBounds.top
  274.     else if nextpoint.v > fTrackBottom then
  275.         nextPoint.v:= fTrackBottom;
  276. END;
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283.